/*
 * Apaga video de uma noticia
 * */
package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dbclass.NoticiaDAO;
import dbclass.NoticiaJDBC;

/**
 * Servlet implementation class NoticiasVideosDelete
 */
public class NoticiasVideosDelete extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NoticiasVideosDelete() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		//Verifica login
		if(session.getValue("autor_login") == null) {
			response.sendRedirect("Home?msg_erro=Acesso Negado");  return;
		} 
		
		
		int id = Integer.parseInt(request.getParameter("id"));
		int id_noticia = Integer.parseInt(request.getParameter("id_noticia"));
		 
		NoticiaDAO noticiaDAO = new NoticiaJDBC();
		try {
			noticiaDAO.deleteVideo((long)id_noticia, (long)id);
			 
			PrintWriter pw = response.getWriter();
			pw.println("<script>window.close(); window.opener.location.reload();</script>");
			 
		} catch (SQLException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
